package com.ruoyi.project.system.uflo.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bstek.uflo.model.HistoryTask;
import com.bstek.uflo.service.HistoryService;
import com.ruoyi.project.system.uflo.mapper.UfloHistoryTaskMapper;
import com.ruoyi.project.system.uflo.model.constant.UfloConstant;
import com.ruoyi.project.system.uflo.model.dto.HistoryTaskDTO;
import com.ruoyi.project.system.uflo.service.IUfloHistoryTaskService;
import com.ruoyi.project.system.user.domain.User;
import com.ruoyi.project.system.user.service.IUserService;

/**
 * UfloHistory
 * @author xianz
 *
 */
@Service
public class UfloHistoryTaskService extends ServiceImpl<UfloHistoryTaskMapper, HistoryTask> implements IUfloHistoryTaskService {


	@Autowired
	HistoryService historyService;
	
	@Autowired
	IUserService userService;
	
	/**
	 * 根据流程实例id获取历史任务记录
	 */
	@Override
	public List<HistoryTaskDTO> getHistoryTasks(long processInstanceId) {
		List<HistoryTask> historyTasks = historyService.getHistoryTasks(processInstanceId);
		List<HistoryTaskDTO> historyTaskDTOs = new ArrayList<HistoryTaskDTO>();
		
		for (HistoryTask historyTask : historyTasks) {
			//排除开始节点
			if(!UfloConstant.NODE_NAME_0.equals(historyTask.getNodeName())) {
				HistoryTaskDTO historyTaskDTO = HistoryTaskDTO.historyTaskToHistoryTaskDTO(historyTask);
				String assignee = historyTaskDTO.getAssignee();
				//将登录名名转换为用户名
				User user = userService.selectUserByLoginName(assignee);
				historyTaskDTO.setAssignee(user.getUserName());
				historyTaskDTOs.add(historyTaskDTO);
			}
		}
		return historyTaskDTOs;
	}

	/**
	 * 查询我的已办列表
	 */
	@Override
	public List<HistoryTaskDTO> selectHistoryList(HistoryTaskDTO historyTaskDTO, User user) {
		return null;
	}

	

}
